package com.hub.grpc.client.config;

import com.hub.grpc.proto.HelloServiceGrpc;
import com.hub.grpc.proto.UserServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ author 飞天蝙蝠
 * @ date & time 2024/12/30 16:14
 */
@Configuration
public class GrpcServiceConfig {

    @Bean
    public ManagedChannel getChannel() {
        return ManagedChannelBuilder.forAddress("localhost", 9091).usePlaintext().build();
    }

    @Bean
    public HelloServiceGrpc.HelloServiceBlockingStub getHelloServiceBlockingStub(ManagedChannel channel) {
        return HelloServiceGrpc.newBlockingStub(channel);
    }

    @Bean
    public UserServiceGrpc.UserServiceBlockingStub getUserServiceBlockingStub(ManagedChannel channel) {
        return UserServiceGrpc.newBlockingStub(channel);
    }
}
